package com.prs.crm.action.cqunicom;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.ResourceBundle;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.annotation.Clew;
import com.prs.crm.context.AppContext;
import com.prs.crm.context.UserLoginStore;
import com.prs.crm.domain.cdxh.SerialNumberss;
import com.prs.crm.domain.cqunicom.BusinessRemind;
import com.prs.crm.domain.cqunicom.Company;
import com.prs.crm.domain.cqunicom.LogSerch;
import com.prs.crm.domain.cqunicom.MidBusinessOrder;
import com.prs.crm.domain.cqunicom.NoteEditor;
import com.prs.crm.domain.cqunicom.PoplarOrder;
import com.prs.crm.domain.cqunicom.Services;
import com.prs.crm.domain.cqunicom.ServicesType;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.service.cdxh.SerialNumberssService;
import com.prs.crm.service.cqunicom.BusinessRemindService;
import com.prs.crm.service.cqunicom.CompanyService;
import com.prs.crm.service.cqunicom.LogSerchService;
import com.prs.crm.service.cqunicom.MidBusinessOrderService;
import com.prs.crm.service.cqunicom.NoteEditorService;
import com.prs.crm.service.cqunicom.OrderService;
import com.prs.crm.service.cqunicom.ServicesService;
import com.prs.crm.service.cqunicom.ServicesTypeService;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2011-3-18 下午03:55:37 简单说明
 */

public class OtherOrderAction extends BaseAction {
	private LogSerchService logSerchService;
	private static final long serialVersionUID = 1L;
	private NoteEditor noteEditor;
	private NoteEditorService noteEditorService;
	private PaginationSupport pagination;
	private BusinessRemind businessRemind;
	private BusinessRemindService businessRemindService;
	private SerialNumberss serialNumberss;

	private SerialNumberssService serialNumberssService;

	private Company company;

	private CompanyService companyService;

	private PoplarOrder order;

	private OrderService orderService;

	private Services services;

	private int juds = 0;

	private List<Services> erList;

	private ServicesService servicesService;

	private ServicesType servicesType;

	private ServicesTypeService servicesTypeService;

	private MidBusinessOrder midBusinessOrder;

	private MidBusinessOrderService midBusinessOrderService;

	private List<ServicesType> tyList;

	private String rowdata;

	private Integer tid;
	/**
	 * 服务类别
	 */
	private Integer serviceClass = 0;
	/**
	 * 服务名称
	 */
	private Integer serverIdsss = 0;
	/**
	 * 服务简写
	 * 
	 * @return
	 */
	private String serverCathy="";
	/**
	 * 地点
	 * 
	 * @return
	 */
	private String addressName;

	/**
	 * 标记是否是简称过来的
	 * 
	 * @return
	 */
	private String sheetJud = "";

	@Action("listAllCompanyFlower")
	public String listAllCompanyFlower() {
		tyList = this.getServicesTypeService().getAllServicesType();
		if ("".equals(sheetJud)) {
			if (serverIdsss == 0
					&& (addressName == null || "".equals(addressName))) {
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				criteria.add(Restrictions.eq("state2", "否"));
				criteria.addOrder(Order.asc("sortNums"));
				criteria.add(Restrictions.eq("comStyles","订花服务"));
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			} else {

				Services ser = this.getServicesService().get(serverIdsss);
				
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				
				if (ser == null) {

				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									ser);
					List<Integer> idList = new ArrayList<Integer>();

					for (MidBusinessOrder oo : midList) {
						idList.add(oo.getCompanym().getId());
					}
				
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}
			
				if (!"所有".equals(addressName)) {
					criteria.add(Restrictions.eq("area", addressName));
				}

				criteria.add(Restrictions.eq("state2", "否"));
				criteria.addOrder(Order.asc("sortNums"));
				//简体判断
				
				if("".equals(serverCathy)){
					
				}else{
				erList = this.getServicesService().getBySheet(serverCathy);
				if (erList == null || erList.size() == 0) {
					criteria.add(Restrictions.eq("state2", "00"));
				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									erList.get(0));

					List<Integer> idList = new ArrayList<Integer>();
					for (MidBusinessOrder oo : midList) {
						
						idList.add(oo.getCompanym().getId());
					}
				
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}}
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			}
		} else {
		
			// sheetJud不为空
			if ("".equals(serverCathy) || serverCathy == null) {
				
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				criteria.add(Restrictions.eq("state2", "00"));
				criteria.addOrder(Order.asc("sortNums"));
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			} else {
				// 根据输入简体查处的services对象
				erList = this.getServicesService().getBySheet(serverCathy);

				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				if (erList == null || erList.size() == 0) {
					criteria.add(Restrictions.eq("state2", "00"));
				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									erList.get(0));

					List<Integer> idList = new ArrayList<Integer>();
					for (MidBusinessOrder oo : midList) {
						
						idList.add(oo.getCompanym().getId());
					}
					
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}
				pagination = this.getPaginationHelper().prepare(pagination);
				criteria.addOrder(Order.asc("sortNums"));
				criteria.add(Restrictions.eq("comStyles","订花服务"));
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));

			}
		}
		return SUCCESS;
	}
	//订票
	@Action("listAllCompanyTicker")
	public String listAllCompanyTicker() {
		tyList = this.getServicesTypeService().getAllServicesType();
		if ("".equals(sheetJud)) {
			if (serverIdsss == 0
					&& (addressName == null || "".equals(addressName))) {
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				criteria.add(Restrictions.eq("state2", "否"));
				criteria.addOrder(Order.asc("sortNums"));
				criteria.add(Restrictions.eq("comStyles","订票服务"));
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			} else {

				Services ser = this.getServicesService().get(serverIdsss);
				
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				
				if (ser == null) {

				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									ser);
					List<Integer> idList = new ArrayList<Integer>();

					for (MidBusinessOrder oo : midList) {
						idList.add(oo.getCompanym().getId());
					}
				
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}
				System.out.println("addressName:" + addressName);
				if (!"所有".equals(addressName)) {
					criteria.add(Restrictions.eq("area", addressName));
				}

				criteria.add(Restrictions.eq("state2", "否"));
				criteria.addOrder(Order.asc("sortNums"));
				//简体判断
				
				if("".equals(serverCathy)){
					
				}else{
				erList = this.getServicesService().getBySheet(serverCathy);
				if (erList == null || erList.size() == 0) {
					criteria.add(Restrictions.eq("state2", "00"));
				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									erList.get(0));

					List<Integer> idList = new ArrayList<Integer>();
					for (MidBusinessOrder oo : midList) {
						
						idList.add(oo.getCompanym().getId());
					}
				
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}}
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			}
		} else {
		
			// sheetJud不为空
			if ("".equals(serverCathy) || serverCathy == null) {
				
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				criteria.add(Restrictions.eq("state2", "00"));
				criteria.addOrder(Order.asc("sortNums"));
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			} else {
				// 根据输入简体查处的services对象
				erList = this.getServicesService().getBySheet(serverCathy);

				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				if (erList == null || erList.size() == 0) {
					criteria.add(Restrictions.eq("state2", "00"));
				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									erList.get(0));

					List<Integer> idList = new ArrayList<Integer>();
					for (MidBusinessOrder oo : midList) {
						
						idList.add(oo.getCompanym().getId());
					}
					for (Integer d : idList) {
						
					}
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}
				pagination = this.getPaginationHelper().prepare(pagination);
				criteria.addOrder(Order.asc("sortNums"));
				criteria.add(Restrictions.eq("comStyles","订票服务"));
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));

			}
		}
		return SUCCESS;
	}
	//订房服务
	@Action("listAllCompanyHome")
	public String listAllCompanyHome() {
		tyList = this.getServicesTypeService().getAllServicesType();
		if ("".equals(sheetJud)) {
			if (serverIdsss == 0
					&& (addressName == null || "".equals(addressName))) {
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				criteria.add(Restrictions.eq("state2", "否"));
				criteria.addOrder(Order.asc("sortNums"));
				criteria.add(Restrictions.eq("comStyles","订房服务"));
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			} else {

				Services ser = this.getServicesService().get(serverIdsss);
				
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				
				if (ser == null) {

				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									ser);
					List<Integer> idList = new ArrayList<Integer>();

					for (MidBusinessOrder oo : midList) {
						idList.add(oo.getCompanym().getId());
					}
				
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}
				System.out.println("addressName:" + addressName);
				if (!"所有".equals(addressName)) {
					criteria.add(Restrictions.eq("area", addressName));
				}

				criteria.add(Restrictions.eq("state2", "否"));
				criteria.addOrder(Order.asc("sortNums"));
				//简体判断
				
				if("".equals(serverCathy)){
					
				}else{
				erList = this.getServicesService().getBySheet(serverCathy);
				if (erList == null || erList.size() == 0) {
					criteria.add(Restrictions.eq("state2", "00"));
				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									erList.get(0));

					List<Integer> idList = new ArrayList<Integer>();
					for (MidBusinessOrder oo : midList) {
						
						idList.add(oo.getCompanym().getId());
					}
				
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}}
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			}
		} else {
		
			// sheetJud不为空
			if ("".equals(serverCathy) || serverCathy == null) {
				
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				criteria.add(Restrictions.eq("state2", "00"));
				criteria.addOrder(Order.asc("sortNums"));
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			} else {
				// 根据输入简体查处的services对象
				erList = this.getServicesService().getBySheet(serverCathy);

				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				if (erList == null || erList.size() == 0) {
					criteria.add(Restrictions.eq("state2", "00"));
				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									erList.get(0));

					List<Integer> idList = new ArrayList<Integer>();
					for (MidBusinessOrder oo : midList) {
						
						idList.add(oo.getCompanym().getId());
					}
					for (Integer d : idList) {
						
					}
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}
				pagination = this.getPaginationHelper().prepare(pagination);
				criteria.addOrder(Order.asc("sortNums"));
				criteria.add(Restrictions.eq("comStyles","订房服务"));
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));

			}
		}
		return SUCCESS;
	}
	//订餐服务
	@Action("listAllCompanyMeal")
	public String listAllCompanyMeal() {
		tyList = this.getServicesTypeService().getAllServicesType();
		if ("".equals(sheetJud)) {
			if (serverIdsss == 0
					&& (addressName == null || "".equals(addressName))) {
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				criteria.add(Restrictions.eq("state2", "否"));
				criteria.addOrder(Order.asc("sortNums"));
				criteria.add(Restrictions.eq("comStyles","订餐服务"));
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			} else {

				Services ser = this.getServicesService().get(serverIdsss);
				
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				
				if (ser == null) {

				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									ser);
					List<Integer> idList = new ArrayList<Integer>();

					for (MidBusinessOrder oo : midList) {
						idList.add(oo.getCompanym().getId());
					}
				
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}
				System.out.println("addressName:" + addressName);
				if (!"所有".equals(addressName)) {
					criteria.add(Restrictions.eq("area", addressName));
				}

				criteria.add(Restrictions.eq("state2", "否"));
				criteria.addOrder(Order.asc("sortNums"));
				//简体判断
				
				if("".equals(serverCathy)){
					
				}else{
				erList = this.getServicesService().getBySheet(serverCathy);
				if (erList == null || erList.size() == 0) {
					criteria.add(Restrictions.eq("state2", "00"));
				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									erList.get(0));

					List<Integer> idList = new ArrayList<Integer>();
					for (MidBusinessOrder oo : midList) {
						
						idList.add(oo.getCompanym().getId());
					}
				
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}}
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			}
		} else {
		
			// sheetJud不为空
			if ("".equals(serverCathy) || serverCathy == null) {
				
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				criteria.add(Restrictions.eq("state2", "00"));
				criteria.addOrder(Order.asc("sortNums"));
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			} else {
				// 根据输入简体查处的services对象
				erList = this.getServicesService().getBySheet(serverCathy);

				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				if (erList == null || erList.size() == 0) {
					criteria.add(Restrictions.eq("state2", "00"));
				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									erList.get(0));

					List<Integer> idList = new ArrayList<Integer>();
					for (MidBusinessOrder oo : midList) {
						
						idList.add(oo.getCompanym().getId());
					}
					for (Integer d : idList) {
						
					}
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}
				pagination = this.getPaginationHelper().prepare(pagination);
				criteria.addOrder(Order.asc("sortNums"));
				criteria.add(Restrictions.eq("comStyles","订餐服务"));
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));

			}
		}
		return SUCCESS;
	}
//一般商家
	@Action("listAllCompany")
	public String listAllCompany() {
		tyList = this.getServicesTypeService().getAllServicesType();

		if ("".equals(sheetJud)) {
			if (serverIdsss == 0
					&& (addressName == null || "".equals(addressName))) {
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				criteria.add(Restrictions.eq("state2", "否"));
				criteria.addOrder(Order.asc("sortNums"));
				criteria.add(Restrictions.eq("comStyles","一般商家"));
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			} else {

				Services ser = this.getServicesService().get(serverIdsss);
				
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				
				if (ser == null) {

				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									ser);
					List<Integer> idList = new ArrayList<Integer>();

					for (MidBusinessOrder oo : midList) {
						idList.add(oo.getCompanym().getId());
					}
				
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}
				
				if (!"所有".equals(addressName)) {
					criteria.add(Restrictions.eq("area", addressName));
				}

				criteria.add(Restrictions.eq("state2", "否"));
				criteria.addOrder(Order.asc("sortNums"));
				//简体判断
				
				if("".equals(serverCathy)){
					
				}else{
				erList = this.getServicesService().getBySheet(serverCathy);
				if (erList == null || erList.size() == 0) {
					criteria.add(Restrictions.eq("state2", "00"));
				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									erList.get(0));

					List<Integer> idList = new ArrayList<Integer>();
					for (MidBusinessOrder oo : midList) {
						
						idList.add(oo.getCompanym().getId());
					}
				
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}}
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			}
		} else {
		
			// sheetJud不为空
			if ("".equals(serverCathy) || serverCathy == null) {
				
				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				criteria.add(Restrictions.eq("state2", "00"));
				criteria.addOrder(Order.asc("sortNums"));
				pagination = this.getPaginationHelper().prepare(pagination);
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));
			} else {
				// 根据输入简体查处的services对象
				erList = this.getServicesService().getBySheet(serverCathy);

				DetachedCriteria criteria = this.getPaginationHelper()
						.createQuery(Company.class);
				if (erList == null || erList.size() == 0) {
					criteria.add(Restrictions.eq("state2", "00"));
				} else {
					List<MidBusinessOrder> midList = this
							.getMidBusinessOrderService().getMidBusinessOrder(
									erList.get(0));

					List<Integer> idList = new ArrayList<Integer>();
					for (MidBusinessOrder oo : midList) {
						
						idList.add(oo.getCompanym().getId());
					}
					
					if (idList.size() == 0) {
						criteria.add(Restrictions.eq("id", 0));
					} else {
						criteria.add(Restrictions.in("id", idList));
					}
				}
				pagination = this.getPaginationHelper().prepare(pagination);
				criteria.addOrder(Order.asc("sortNums"));
				criteria.add(Restrictions.eq("comStyles","一般商家"));
				this.setPagination(this.getCompanyService().listByPage(
						criteria, pagination));

			}
		}
		return SUCCESS;
	}
	
	
	
	@Action(value = "serviceByServerType", results = { @Result(name = "success", type = "json", params = {
			"root", "rowdata" }) })
	public String serviceByServerType() {
		ServicesType types = this.getServicesTypeService().get(tid);
		List<Services> lists = this.getServicesService().getByStyle(types);
		String objs = "";
		for (Services ss : lists) {
			if ("".equals(objs)) {
				objs = ss.getId() + "-" + ss.getName();
			} else {
				objs = objs + "," + ss.getId() + "-" + ss.getName();
			}
		}
		this.rowdata = objs;
		return SUCCESS;
	}
	/**
	 * 关闭操作
	 */
	
	@Action(value = "closeWins", results = { @Result(name = "success", type = "json", params = {
			"root", "rowdata" }) })
	public String closeWins() {
		Person account = AppContext.getAccountContext().getUser();
		UserLoginStore.removeUser(account);
		System.out.println("退出");
		this.rowdata = "CLOSE";
		return SUCCESS;
	}
	
	@Action("lookCompany")
	public String lookCompany() {
		
		Company com=this.getCompanyService().get(company.getId());
		if(com!=null)
		{
		int yNums=0;
		
			yNums=com.getClickTimes()+1;//数字加
		
		int times=com.getLevels()*yNums;
        com.setClickTimes(yNums);	
		com.setSortNums(times);
		this.getCompanyService().submit(com);
		}
		
		if ("".equals(services) || services == null) {
		} else {
			String ss = services.getWorkPattern();
			if (ss.equals("派单")) {
				juds = 1;
			} else if (ss.equals("转接")) {
				juds = 2;
			}
		}
		return SUCCESS;
	}

	/**
	 * 派单
	 * 
	 * @return
	 */
	@Action("otherDispatch")
	public String otherDispatch() {
		services = this.getServicesService().get(services.getId());
		rowdata = getSerialCode(services);
		company = this.getCompanyService().get(company.getId());

		return SUCCESS;
	}

	/**
	 * 转接
	 * 
	 * @return
	 */
	@Action("otherduplexing")
	public String otherduplexing() {
		services = this.getServicesService().get(services.getId());
		rowdata = getSerialCode(services);
		company = this.getCompanyService().get(company.getId());
		return SUCCESS;
	}

	/**
	 * 创建派单
	 * 
	 * @return
	 * @throws UnsupportedEncodingException
	 * @throws MalformedURLException
	 */
	@Clew(results = { "success", "none" })
	@Action(value = "saveOtherDispatch", results = {
			@Result(name = "success", type = "redirect", location = "lookCompany"),
			@Result(name = "none", type = "redirect", location = "lookCompany"),
			@Result(name = "error", type = "chain", location = "lookCompany") })
	public String saveOtherDispatch() throws MalformedURLException,
			UnsupportedEncodingException {
		LogSerch log = new LogSerch();
		log.setCandlePeron(AppContext.getAccountContext().currentUser()
				.getUserName());
		log.setCandleContents("创建了派单");
		this.getLogSerchService().save(log);
		services = this.getServicesService().get(services.getId());
		company = this.getCompanyService().get(company.getId());
		order.setModleName("派单");
		order.setServices(services);
		order.setCompany(company);
		order.setOrderStyles(2);// 1:是手工单 2：不是手工单
		order.setOrderDate(new Date());
		order.setRemindTime(0);
		order.setNewOrderState("1");
		order.setHuifangUpdate("否");
		order.setPerson(AppContext.getAccountContext().currentUser());
		order.setAudState(0);
		order.setTredeSatets(0);
		order.setPriColor(0);
		this.getOrderService().save(order);
		
		String contents=getContents(services,company);
		String contgg="尊敬的客户你有要处理的派单信息";
		if("".equals(contents)){
			
		}else{
			contgg=contents;
		}
	


		
		
		
		sendSMS4Other(company.getPhone1(), contgg, new Date() + "");
		this.setPrompt("数据处理中...");

		BusinessRemind  br=new BusinessRemind();
		br.setCompanyRemind(company);
		br.setReadYN("1");
		br.setRemindOrder(order);
		this.getBusinessRemindService().save(br);
		return SUCCESS;
	}

	/**
	 * 创建转接
	 * 
	 * @return
	 * @throws UnsupportedEncodingException
	 * @throws MalformedURLException
	 */
	@Clew(results = { "success", "none" })
	@Action(value = "saveOtherDuplexing", results = {
			@Result(name = "success", type = "redirect", location = "lookCompany"),
			@Result(name = "none", type = "redirect", location = "lookCompany"),
			@Result(name = "error", type = "chain", location = "lookCompany") })
	public String saveOtherDuplexing() throws MalformedURLException,
			UnsupportedEncodingException {
		LogSerch log = new LogSerch();
		log.setCandlePeron(AppContext.getAccountContext().currentUser()
				.getUserName());
		log.setCandleContents("创建了转接单");
		this.getLogSerchService().save(log);
		services = this.getServicesService().get(services.getId());
		company = this.getCompanyService().get(company.getId());
		order.setModleName("转接");
		order.setServices(services);
		order.setCompany(company);
		order.setOrderStyles(2);// 1:是手工单 2：不是手工单
		order.setOrderDate(new Date());
		order.setRemindTime(0);
		order.setNewOrderState("1");
		order.setHuifangUpdate("否");
		order.setPerson(AppContext.getAccountContext().currentUser());
		order.setAudState(0);
		order.setTredeSatets(0);
		order.setPriColor(0);
		this.getOrderService().save(order);
		String contents=getContents(services,company);
		String contgg="尊敬的客户你有要处理的派单信息";
		if("".equals(contents)){
			
		}else{
			contgg=contents;
		}
	
		sendSMS4Other(company.getPhone1(),contgg, new Date() + "");
		this.setPrompt("数据处理中...");
		

		BusinessRemind  br=new BusinessRemind();
		br.setCompanyRemind(company);
		br.setReadYN("1");
		br.setRemindOrder(order);
		this.getBusinessRemindService().save(br);
		return SUCCESS;
	}
	
	@Action(value = "serverCathyx", results = { @Result(name = "success", type = "json", params = {
			"root", "rowdata" }) })
	public String serverCathyx() {
		String returnsV="";
		String comstyles="";
		int sortNum=0;
		int serid=0;
		int  cid=0;
		erList = this.getServicesService().getBySheet(serverCathy);
		
		if (erList == null || erList.size() == 0) {
			returnsV="A";
		} else {
        List<MidBusinessOrder> midList = this.getMidBusinessOrderService().getMidBusinessOrder(erList.get(0));
        List<Integer> idList = new ArrayList<Integer>();
        
     
        for (MidBusinessOrder oo : midList) {
        comstyles=oo.getCompanym().getComStyles();
        if(sortNum==0){
        	sortNum=oo.getCompanym().getSortNums();	
        	cid=oo.getCompanym().getId();//公司ID
    	    serid=oo.getServicesm().getId();//服务ID
        }else{
        	if(oo.getCompanym().getSortNums()<sortNum){
        		sortNum=oo.getCompanym().getSortNums();	
            	cid=oo.getCompanym().getId();//公司ID
        	    serid=oo.getServicesm().getId();//服务ID
        	}
        }
	     idList.add(oo.getCompanym().getId());
	    
	     
	    
         }
    
        
        if(idList.size()>0){
        	returnsV="B,"+comstyles+","+cid+","+serid;	
        }else{
        	returnsV="A, ";	
        }
       
         
		}
		this.rowdata = returnsV;
	
 		return SUCCESS;
}
		
		
		
		

	public PaginationSupport getPagination() {
		return pagination;
	}

	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public Company getCompany() {
		return company;
	}

	public String getRowdata() {
		return rowdata;
	}

	public void setRowdata(String rowdata) {
		this.rowdata = rowdata;
	}

	public Integer getTid() {
		return tid;
	}

	public Integer getServerIdsss() {
		return serverIdsss;
	}

	public void setServerIdsss(Integer serverIdsss) {
		this.serverIdsss = serverIdsss;
	}

	public String getServerCathy() {
		return serverCathy;
	}

	public void setServerCathy(String serverCathy) {
		this.serverCathy = serverCathy;
	}

	public String getAddressName() {
		return addressName;
	}

	public void setAddressName(String addressName) {
		this.addressName = addressName;
	}

	public void setTid(Integer tid) {
		this.tid = tid;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public CompanyService getCompanyService() {
		return companyService;
	}

	public void setCompanyService(CompanyService companyService) {
		this.companyService = companyService;
	}

	public PoplarOrder getOrder() {
		return order;
	}

	public void setOrder(PoplarOrder order) {
		this.order = order;
	}

	public OrderService getOrderService() {
		return orderService;
	}

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	public Services getServices() {
		return services;
	}

	public void setServices(Services services) {
		this.services = services;
	}

	public ServicesService getServicesService() {
		return servicesService;
	}

	public void setServicesService(ServicesService servicesService) {
		this.servicesService = servicesService;
	}

	public ServicesType getServicesType() {
		return servicesType;
	}

	public void setServicesType(ServicesType servicesType) {
		this.servicesType = servicesType;
	}

	public ServicesTypeService getServicesTypeService() {
		return servicesTypeService;
	}

	public void setServicesTypeService(ServicesTypeService servicesTypeService) {
		this.servicesTypeService = servicesTypeService;
	}

	public List<ServicesType> getTyList() {
		return tyList;
	}

	public void setTyList(List<ServicesType> tyList) {
		this.tyList = tyList;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getSheetJud() {
		return sheetJud;
	}

	public void setSheetJud(String sheetJud) {
		this.sheetJud = sheetJud;
	}

	public MidBusinessOrder getMidBusinessOrder() {
		return midBusinessOrder;
	}

	public void setMidBusinessOrder(MidBusinessOrder midBusinessOrder) {
		this.midBusinessOrder = midBusinessOrder;
	}

	public MidBusinessOrderService getMidBusinessOrderService() {
		return midBusinessOrderService;
	}

	public void setMidBusinessOrderService(
			MidBusinessOrderService midBusinessOrderService) {
		this.midBusinessOrderService = midBusinessOrderService;
	}

	public int getJuds() {
		return juds;
	}

	public void setJuds(int juds) {
		this.juds = juds;
	}

	public String getSerialCode(Services ser) {
		SerialNumberss snb = this.getSerialNumberssService()
				.getSerialNumberssOrder(ser.getName(), ser.getSimplename());
		if (snb != null) {
			// 不为空
			String currentString = backmidleValue();
			String dbString = snb.getStyNumberCode();
			String ak[] = dbString.split(currentString);
			int lengths = ak.length;
			if (lengths == 2) {
				String codes = ak[0] + backmidleValue() + addtional(ak[1]);
				snb.setStyNumberCode(codes);
				this.getSerialNumberssService().submit(snb);
				return codes;
			} else {
				String codes = ser.getSimplename() + backmidleValue() + "0001";
				snb.setStyNumberCode(codes);
				this.getSerialNumberssService().submit(snb);
				return codes;
			}

		} else {
			// 为空的时候
			String codes = ser.getSimplename() + backmidleValue() + "0001";
			SerialNumberss ss = new SerialNumberss();
			ss.setJudgStyle(ser.getName());
			ss.setStyNumberCode(codes);
			ss.setStyCategory(ser.getSimplename());
			this.getSerialNumberssService().save(ss);
			return codes;
		}

	}

	public String backmidleValue() {
		SimpleDateFormat gs = new SimpleDateFormat("yyyy-MM-dd");
		String currentDate = gs.format(new Date());
		String currents = currentDate.replace("-", "");
		return currents;
	}

	public String addtional(String numbe) {
		int startNum = Integer.parseInt(numbe);
		String endNun = (startNum + 1) + "";
		int cicles = 4 - endNun.length();
		for (int i = 0; i < cicles; i++) {
			endNun = "0" + endNun;
		}
		return endNun;
	}

	public SerialNumberss getSerialNumberss() {
		return serialNumberss;
	}

	public void setSerialNumberss(SerialNumberss serialNumberss) {
		this.serialNumberss = serialNumberss;
	}

	public SerialNumberssService getSerialNumberssService() {
		return serialNumberssService;
	}

	public void setSerialNumberssService(
			SerialNumberssService serialNumberssService) {
		this.serialNumberssService = serialNumberssService;
	}

	public Integer getServiceClass() {
		return serviceClass;
	}

	public void setServiceClass(Integer serviceClass) {
		this.serviceClass = serviceClass;
	}

	public LogSerchService getLogSerchService() {
		return logSerchService;
	}

	public void setLogSerchService(LogSerchService logSerchService) {
		this.logSerchService = logSerchService;
	}

	public List<Services> getErList() {
		return erList;
	}

	public void setErList(List<Services> erList) {
		this.erList = erList;
	}

	@SuppressWarnings("unused")
	private static int sendSMS4Other(String Mobile, String Content,
			String send_time) throws MalformedURLException,
			UnsupportedEncodingException {
		ResourceBundle rb = ResourceBundle.getBundle("note");
		URL url = null;
		String CorpID = rb.getString("userName");// 账户名
		String Pwd = rb.getString("password");// 密码
		String send_content = URLEncoder.encode(
				Content.replaceAll("<br/>", " "), "GBK");// 发送内容
		url = new URL("http://mb345.com/WS/Send.aspx?CorpID=" + CorpID
				+ "&Pwd=" + Pwd + "&Mobile=" + Mobile + "&Content="
				+ send_content + "&Cell=&SendTime=" + send_time);
		BufferedReader in = null;
		int inputLine = 0;
		try {
			//System.out.println("开始发送短信手机号码为 ：" + Mobile);
			in = new BufferedReader(new InputStreamReader(url.openStream()));
			inputLine = new Integer(in.readLine()).intValue();
		} catch (Exception e) {
			//System.out.println("网络异常,发送短信失败！");
			inputLine = -9;
		}
		//System.out.println("结束发送短信返回值：  " + inputLine);
		return inputLine;
	}

	public BusinessRemind getBusinessRemind() {
		return businessRemind;
	}

	public void setBusinessRemind(BusinessRemind businessRemind) {
		this.businessRemind = businessRemind;
	}

	public BusinessRemindService getBusinessRemindService() {
		return businessRemindService;
	}

	public void setBusinessRemindService(BusinessRemindService businessRemindService) {
		this.businessRemindService = businessRemindService;
	}
	public String getContents(Services sss,Company com){
		  Services ss=this.getServicesService().get(sss.getId());
			List<NoteEditor> neList=this.getNoteEditorService().getByServicesNoteEditor(ss);
			String contents="";
			for(NoteEditor  ne:neList){
			String ser[]=(ne.getSerialName()).split(",");
			for(String s:ser){
				if("".equals(s)){
					
				}else{
				if(com.getId()==Integer.parseInt(s)){
					contents=ne.getInforMo();
				}	
				}
				
			}
			
			}
			return contents;
	  }

	public NoteEditor getNoteEditor() {
		return noteEditor;
	}

	public void setNoteEditor(NoteEditor noteEditor) {
		this.noteEditor = noteEditor;
	}

	public NoteEditorService getNoteEditorService() {
		return noteEditorService;
	}

	public void setNoteEditorService(NoteEditorService noteEditorService) {
		this.noteEditorService = noteEditorService;
	}
	
}
